package com.propertree.mailer.helper;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.propertree.mailer.config.MailerConfigContainer;

public class ValidatorHelper {

	public static final String SEPERATOR = System.getProperty("line.separator");

	public List<String> validateFilePath(String filePath, String ext) {
		List<String> errList = new ArrayList<String>();
		if (filePath == null || filePath.trim().equals("")) {
			errList.add("One more more file paths are not given or not legal. Please check the path properly."
					+ SEPERATOR);
			// System.exit(-1);
		}

		File file = new File(filePath);
		if (!file.exists()) {
			errList.add("File :: " + filePath + " doesn't exist. Please check the path properly." + SEPERATOR);
			// System.exit(-1);
		}

		if (!file.canRead()) {
			errList.add("File :: " + filePath + " can't be read. Please check file permission." + SEPERATOR);
			// System.exit(-1);
		}

		if (!file.isFile()) {
			errList.add("File :: " + filePath + " seems a directory. Please check properly." + SEPERATOR);
			// System.exit(-1);
		}
		String fileName = file.getName();
		int dot = fileName.lastIndexOf('.');
		if (dot <= 0) {
			errList.add("File :: " + filePath + " doesn't seem to have proper extension. Check it is 'xls' file."
					+ SEPERATOR);
			// System.exit(-1);
		}
		String extension = (dot == -1) ? "" : fileName.substring(dot + 1);

		if (!ext.equalsIgnoreCase(extension)) {
			errList.add("File :: " + filePath + " doesn't seem to have proper extension. Check it is '" + ext
					+ "' file." + SEPERATOR);
			// System.exit(-1);
		}

		return errList;
	}

/*	public static int getValidField(MailerConfigContainer mailerConfigContainer) {
		List<String> errList = new ArrayList<String>();
		if (blockSizeStr == null || blockSizeStr.trim().equals("")) {
			errList.add(propertyName + " is not proper." + SEPERATOR);
			System.exit(-1);
		}
		int returnCode = 0;
		try {
			mailerConfigContainer.getMailPubConfig().setBlockSize(Integer.parseInt(blockSizeField.getText()));
		} catch (Exception e) {
			returnCode = -1;
			System.out.println("Block size is not corrent. Remove and enter again.");
			// System.e
		}
		try {
			mailerConfigContainer.getMailPubConfig().setPausePerBlockInMiilis(
					Long.parseLong(pausePerBlockField.getText()));
		} catch (Exception e) {
			returnCode = -1;
			System.out.println("Pause per block is not correct. Remove and enter again.");
		}
		try {
			mailerConfigContainer.getMailPubConfig().setPausePerMessageInMillis(
					Long.parseLong(pausePerBlockField.getText()));
		} catch (Exception e) {
			returnCode = -1;
			System.out.println("Pause per message is not corret. Remove and enter again.");
		}
		try {
			mailerConfigContainer.getMailPubConfig().setDelayedStartInMillis(
					Long.parseLong(delayedStartField.getText()));
		} catch (Exception e) {
			returnCode = -1;
			System.out.println("Delayed start is not correct. Remove and enter again.");
		}
		return returnCode;
		return blockSize;
	}*/
}
